package terra.model.effect;

import java.util.ArrayList;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;

import terra.model.ClientWeather;
import terra.model.Weather;
import terra.slick.GameState;

public class WeatherEffect extends AbstractEffect {

	Weather weather;
	ArrayList<Vector2f> vec = new ArrayList<Vector2f>();
	
	public WeatherEffect(ClientWeather clientWeather) {
		weather = clientWeather;
		this.time = Integer.MAX_VALUE;
	}

	@Override
	public void draw(Graphics g) {
		g.setColor(GameState.waterColor);
		for(int i = 0; i < vec.size();i++){
			Vector2f v = vec.get(i);
			g.drawLine(v.getX()+GameState.getInstance().getOffsetX(), v.getY()+GameState.getInstance().getOffsetY(),
					v.getX()+GameState.getInstance().getOffsetX(), v.getY()+GameState.getInstance().getOffsetY()+8);
		}
	}

	@Override 
	public void update(int delta){
		super.update(delta);
		if (weather.intensity > 0.1f)
			for(int i = 0; i < weather.intensity*7;i++)
				vec.add(new Vector2f(-150+ GameState.rnd.nextInt(GameState.getInstance().getGc().getWidth()+300),-32));
				
		for(int i = 0; i < vec.size();i++){
			Vector2f v = vec.get(i);
			v.add(new Vector2f(-0.5f,2f));
			if (v.getY() > GameState.getInstance().getGc().getHeight())
				vec.remove(i);
		}
	}
	
	@Override
	public void end() {
		
	}

}
